package com.ruoyi.safe.controller.api;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.safe.domain.CommonCooperatorClass;
import com.ruoyi.safe.domain.dto.BaseAppDTO;
import com.ruoyi.safe.domain.dto.CommonCooperatorClassAppDTO;
import com.ruoyi.safe.domain.vo.CommonCooperatorClassVO;
import com.ruoyi.safe.service.ICommonCooperatorClassService;
import com.ruoyi.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 企业班组(app端)----->张鹏
 *
 * @author zhangpeng
 * @date 2024-01-23
 */

@RestController
@RequestMapping("/api/cooperator/class")
public class CooperatorClassController extends BaseController {

    @Autowired
    ICommonCooperatorClassService commonCooperatorClassService;
    @Autowired
    ISysUserService sysUserService;
    /**
     * 根据项目id查询班组
     */
    @PostMapping("/listByProjectId")
    public AjaxResult listByProjectId(@RequestBody BaseAppDTO baseAppDTO) {
        SysUser sysUser = sysUserService.selectUserByUserName(baseAppDTO.getUserName());
        if (sysUser == null) {
            throw new ServiceException(StringUtils.format("用户信息不存在：{}", baseAppDTO.getUserName()));
        }
        return success(commonCooperatorClassService.selectCommonCooperatorClassByProjectId(baseAppDTO.getProjectId()));
    }
}
